import { defineStore } from "pinia";
import { UserState } from "@/stores/interface/user";

export const useUserStore = defineStore({
  id: "admin-user",
  state: (): UserState => ({
    token: "",
    userInfo: { name: "Tom" }
  }),
  getters: {
    tokenGet: state => state.token,
    userInfoGet: state => state.userInfo
  },
  actions: {
    // Set Token
    setToken(token: string) {
      this.token = token;
    },
    // Set setUserInfo
    setUserInfo(userInfo: UserState["userInfo"]) {
      this.userInfo = userInfo;
    },
    // Clear user
    clearInfo() {
      this.token = "";
      this.userInfo = { name: "Tom" };
    }
  },
  persist: true
});
